<template>
	<view>
		<uni-section title="意见反馈" type="line">
			<view class="px-3">
				<textarea v-model="feedback" maxlength="200" class="py-2 pl-2 pr-1 border w-100 rounded" cols="30"
					rows="10" style="background-color: #eee; box-sizing: border-box"
					placeholder="请描述您遇到的问题或对本产品的建议..."></textarea>

				<view class="mt-2 text-light-black">您还可以发送邮件到：via668@yeah.net</view>
			</view>

		</uni-section>

		<view class="fixed-bottom px-3" style="bottom: 100rpx;">
			<button :disabled="disabled" type="primary" @click="submit">提交</button>
		</view>
	</view>
</template>

<script setup>
	import {
		computed,
		ref
	} from 'vue';
	import {
		useStore
	} from 'vuex';
	import apis from '@/apis/index.js';
	import $T from '@/common/time.js';

	const store = useStore();
	const {
		token,
		user
	} = store.state;
	const feedback = ref('');
	const disabled = computed(() => {
		if ((feedback.value === '') || (feedback.value.length <= 5)) {
			return true
		}
		return false;
	});

	const submit = () => {
		apis.feedback({
				feedback: feedback.value,
				user_id: user.id,
				date: $T.dateFormat(new Date(), '{Y}-{MM}-{DD} {hh}:{ii}:{ss}')
			}, {
				token
			})
			.then(res => {
				const {
					success,
					msg
				} = res;
				uni.showToast({
					title: msg,
					icon: success ? 'success' : 'error'
				});
				if (success) feedback.value = '';
			})
			.catch(e => {
				uni.showToast({
					title: '请稍后再试',
					icon: 'error'
				});
			});
	}
</script>

<style>

</style>
